package Demo01;
/*String[] students=new String[3];
//1.存储全班同学姓名
//addStudentName(students);
//2.打印全班同学每一个人的名字
//printStudentName(students);
//3.获取随机点名到学生姓名并打印
//randomStudentName(students);
 * 
 */
import java.util.Random;
import java.util.Scanner;

public class RandomDemo {
    public static void main(String[] args) {
        String[] students = new String[3];
        addStudentName(students);
        printStudentName(students);
        randomStudentName(students);
    }

    private static void addStudentName(String[] students) {
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < students.length; i++) {
            System.out.print("请输入第 " + (i + 1) + " 个学生的姓名：");
            students[i] = sc.nextLine();
        }
    }

    private static void printStudentName(String[] students) {
        for (int i = 0; i < students.length; i++) {
            System.out.println("第 " + (i + 1) + " 个学生的姓名是：" + students[i]);
        }
    }

    private static void randomStudentName(String[] students) {
        Random random = new Random();
        int index = random.nextInt(students.length);
        System.out.println("幸运儿：" + students[index]);
    }
}
